package com.atguigu.gmall.secKill.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author ZengMing
 * @Date 2021/7/16 18:39
 * @Description:秒杀相关的交换机和队列绑定的创建
 */
@Configuration
public class SeckillRabbitConfig {

    /**
     * 创建秒杀的交换机
     * @return
     */
    @Bean("seckillExchange")
    public Exchange seckillExchange(){
        return ExchangeBuilder.topicExchange("seckill_exchange").build();
    }

    /**
     * 创建秒杀的队列
     * @return
     */
    @Bean("seckillQueue")
    public Queue seckillQueue(){
        return QueueBuilder.durable("seckill_queue").build();
    }

    /**
     * 创建绑定
     * @param seckillExchange
     * @param seckillQueue
     * @return
     */
    @Bean
    public Binding seckillBinding(@Qualifier("seckillExchange") Exchange seckillExchange,
                                  @Qualifier("seckillQueue") Queue seckillQueue){
        return BindingBuilder.bind(seckillQueue).to(seckillExchange).with("seckill.#").noargs();
    }
}
